import {HttpUtil} from "../utils/HttpUtil";
import {CookieUtil} from "../utils/CookieUtil";
import {Base64} from 'js-base64';
import {LayerUtil} from "../utils/LayerUtil";
import {CONST} from "../base/constant";


export const getRecordsAction = (filter) => {

    const url = CONST.API_PREFIX + "/user/1/record";

    return new Promise(function (resove,reject) {
        HttpUtil.get(url,filter).then(function (txt) {
            if(txt){
                const res = JSON.parse(txt);
                resove(res);
            }else{
                LayerUtil.toast('接口错误');
            }
        }).catch(function (err) {
            reject(err);
        });
    })

};


export const getRecordsByIdAction = (id) => {

    const url = CONST.API_PREFIX + "/record/" + id;

    return new Promise(function (resove,reject) {
        HttpUtil.get(url).then(function (txt) {
            const res = txt ? JSON.parse(txt) : {};
            resove(res);
        }).catch(function (err) {
            reject(err);
        });
    })

};

export const updateRecordByIdAction = (param) => {

    const url = CONST.API_PREFIX + "/record/" + param.id;

    return new Promise(function (resove,reject) {
        HttpUtil.post(url,param).then(function (txt) {
            const res = JSON.parse(txt);
            resove(res);
        }).catch(function (err) {
            reject(err);
        });
    })

};

export const newRecordByIdAction = (param) => {

    const url = CONST.API_PREFIX + "/user/1/record";

    return new Promise(function (resove,reject) {
        HttpUtil.post(url,param).then(function (txt) {
            const res = JSON.parse(txt);
            resove(res);
        }).catch(function (err) {
            reject(err);
        });
    })

};


export const updateRecordStaticByIdAction = (param) => {

    const url = CONST.API_PREFIX + "/record/static/" + param.id;

    return new Promise(function (resove,reject) {
        HttpUtil.post(url,param).then(function (txt) {
            const res = JSON.parse(txt);
            resove(res);
        }).catch(function (err) {
            reject(err);
        });
    })

};